package com.oazon.moco.link.core;

import io.netty.channel.ChannelHandlerContext;

import java.util.List;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;

import com.moco.launcher.LauncherApplication;
import com.oazon.common.SettingType;
import com.oazon.common.Settings;
import com.oazon.common.util.DriveUUIDUtil;
import com.oazon.moco.bean.McServiceMsg;
import com.oazon.moco.lan.LanServerManage;
import com.oazon.moco.lan.core.controldriver.bean.ControlDriver;
import com.oazon.moco.lan.core.http.bean.AVTransportUri;
import com.oazon.moco.lan.core.http.bean.DeleteBean;
import com.oazon.moco.lan.core.http.bean.FavoriteBean;
import com.oazon.moco.lan.core.http.bean.MediaStateInstance;
import com.oazon.moco.lan.core.http.bean.PositionInfo;
import com.oazon.moco.lan.core.http.bean.ResponseUriToQueue;
import com.oazon.moco.lan.core.http.bean.ResponseVolume;
import com.oazon.moco.lan.core.http.bean.Seek;
import com.oazon.moco.lan.core.http.bean.SongInfo;
import com.oazon.moco.lan.core.http.bean.UriToQueue;
import com.oazon.moco.lan.core.http.bean.VolumeInstance;
import com.oazon.moco.lan.core.http.bean.ZoneInfo;
import com.oazon.moco.link.core.source.LinkEventSource;
import com.oazon.moco.link.event.BatteryEvent;
import com.oazon.moco.link.event.BatteryStatus;
import com.oazon.moco.link.event.EQEvent;
import com.oazon.moco.link.event.LanEvent;
import com.oazon.moco.link.event.LanStatus;
import com.oazon.moco.link.event.PlayerEvent;
import com.oazon.moco.link.event.PlayerStatus;
import com.oazon.moco.link.event.RequestEvent;
import com.oazon.moco.link.event.RequestStatus;
import com.oazon.moco.link.event.ResponceEvent;
import com.oazon.moco.link.event.ResponceStatus;
import com.oazon.moco.link.event.SpechEvent;
import com.oazon.moco.link.event.SpeechStatus;
import com.oazon.moco.link.event.SystemStateEvent;
import com.oazon.moco.link.event.SystemStatus;
import com.oazon.moco.link.event.UpdateEvent;
import com.oazon.moco.link.event.UpdateStatus;
import com.oazon.moco.playlist.PlayListManage;
import com.oazon.moco.serialport.SerialHandlerService;
import com.oazon.moco.serialport.WeightServer;
import com.oazon.system.SystemService;
import com.oazon.system.WifiService;
import com.oazon.system.broadcast.ShutDownReceive;
import com.oazon.voicelib.model.SemanticObj;
import com.oazon.voicelib.service.SpeechManage;

public class LinkSDK implements ILinkEventController, ILinkEventService {

	public static String UUID = "";
	public static final int PORT = 55688;
	public static int curVolume = 0;

	public static String JMDNS_SERVICE_NAME = "O2Player";

	public static final boolean DEBUG_LOCK = true;

	public static boolean canOperaSerial = true;

	private static Context context = null;
	private static LinkSDK instance = null;

	private static Intent wifiServiceIntent;
	private static Intent systemService;
	private static Intent collectionService;
	private static Intent serialService;
	private static Intent weightServer;
	private static LauncherApplication lApplication = null;

	public static void init(Context ctx) {

		curVolume = Settings.getInstance(ctx).getInt(
				SettingType.VOLUME.value(), 13);
		getInstance();
		context = ctx;

		if (!Settings.getInstance(context).get("uuid", "").equals("")) {
			UUID = Settings.getInstance(context).get("uuid");
		} else {
			UUID = DriveUUIDUtil.getDriverUUID(context);
			Settings.getInstance(context).set("uuid", UUID);
		}

		Log.d("uuid", "uuid == " + UUID);
		LanServerManage.initServerManage(context);
		SpeechManage.init(context);
		PlayListManage.init(context);
		SpeechManage.getInstance();

		initService();

		lApplication = (LauncherApplication) context.getApplicationContext();

		new ShutDownReceive(context) {

			@Override
			public void onReceiveShoutDown(Context context) {

			}
		};

		/*
		 * // 拿到键盘守护锁，解锁屏幕 KeyguardManager keyguardManager = (KeyguardManager)
		 * context.getSystemService(Context.KEYGUARD_SERVICE); KeyguardLock
		 * keyguardLock = keyguardManager.newKeyguardLock("");
		 * keyguardLock.disableKeyguard();
		 */
	}

	private static void initService() {

		wifiServiceIntent = new Intent(context, WifiService.class);
		context.bindService(wifiServiceIntent, wifiServiceConnection,
				Context.BIND_AUTO_CREATE);

		systemService = new Intent(context, SystemService.class);
		context.startService(systemService);

		serialService = new Intent(context, SerialHandlerService.class);
		context.startService(serialService);
		weightServer = new Intent(context, WeightServer.class);
		context.startService(weightServer);
	}

	/**
	 * 关闭资源占用
	 */
	public static void destroy() {
		LinkSDK.getInstance().closeService(
				LinkEventController.systemEventSource);
		context.unbindService(wifiServiceConnection);
		context.stopService(systemService);
		context.stopService(collectionService);
		context.stopService(serialService);
		context.stopService(weightServer);
		SpeechManage.getInstance().destroy();
	}

	private static ServiceConnection wifiServiceConnection = new ServiceConnection() {

		@Override
		public void onServiceDisconnected(ComponentName arg0) {

		}

		@Override
		public void onServiceConnected(ComponentName arg0, IBinder arg1) {

		}
	};

	public static Context getAppContext() {
		return context;
	}

	public static String getUUid() {
		return UUID;
	}

	private LinkSDK() {
	}

	public synchronized static LinkSDK getInstance() {
		if (instance == null) {
			instance = new LinkSDK();
		}
		return instance;
	}

	/**
	 * 播放时候调用
	 * 
	 * @param speed
	 * @param instanceID
	 */
	@Override
	public void play(LinkEventSource source, int instanceID, int speed) {
		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.PLAY);
		event.setInstanceID(instanceID);
		event.setSpeed(speed);
		LinkEventController.getInstance().notifyListeners(event);
	}

	// ************************Controller************************

	/**
	 * 注册监听器
	 */
	@Override
	public void registLinkListener(LinkEventListener listener) {
		LinkEventController.getInstance().registLinkListener(listener, true);
	}

	/**
	 * 注册监听器
	 */
	@Override
	public void registLinkListener(LinkEventListener listener, boolean singleton) {
		LinkEventController.getInstance().registLinkListener(listener,
				singleton);
	}

	/**
	 * 取消注册监听
	 */
	@Override
	public void unregistLinkListener(LinkEventListener listener) {
		LinkEventController.getInstance().unregistLinkListener(listener);
	}

	@Override
	public void notify(String uuid, LinkEvent Event) {
		LinkEventController.getInstance().notify(uuid, Event);
	}

	@Override
	public void notify(LinkEventSource source, LinkEvent event) {
		LinkEventController.getInstance().notify(source, event);
	}

	@Override
	public void notifyListeners(LinkEvent event) {
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 请求得到硬件版本号
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestHardWareVersion(LinkEventSource source) {

		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.HARDWARE_VERSION);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 请求得到充电状态
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestChage(LinkEventSource source) {

		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.CHARGE);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 请求得到充电状态
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestFull(LinkEventSource source) {

		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.FULL);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 请求得到充电的百分比
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestChagePercent(LinkEventSource source) {

		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.PERCENT);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 请求得到外接电源的接入状态
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestExternalBatteryin(LinkEventSource source) {

		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.EXTERNAL_BATTERY_IN);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 设置关机之后等n秒重启指令
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 * @param time
	 *            单位s
	 */
	@Override
	public void setShutdoneOpentime(LinkEventSource source, int time) {

		SystemStateEvent event = new SystemStateEvent(source);
		event.setShutdownToOpenTime(time);
		event.setWorkStatus(SystemStatus.SHUTDOWN_TO_OPEN_TIME);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 请求关机
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void isShutdone(LinkEventSource source) {

		SystemStateEvent event = new SystemStateEvent(source);
		event.setWorkStatus(SystemStatus.SHUTDONW);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 关机之后等n秒重启取消指令
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void isShutdoneOpenCancel(LinkEventSource source) {

		SystemStateEvent event = new SystemStateEvent(source);
		event.setWorkStatus(SystemStatus.SHUTDOWN_OPEN_CANCLE);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 进入待机
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void isWait(LinkEventSource source) {
		SystemStateEvent event = new SystemStateEvent(source);
		event.setWorkStatus(SystemStatus.WAIT);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 进入正常
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void isNormal(LinkEventSource source) {

		SystemStateEvent event = new SystemStateEvent(source);
		event.setWorkStatus(SystemStatus.NORMAL);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 开机完成
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void isOpendone(LinkEventSource source) {

		SystemStateEvent event = new SystemStateEvent(source);
		event.setWorkStatus(SystemStatus.OPENDOWN);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 选择音效
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void chooseEQ(LinkEventSource source, byte b) {

		EQEvent event = new EQEvent(source);
		event.setChoose_EQ(b);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 发送音效文件
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void sendEQFile(LinkEventSource source, int[] eq_h, int[] eq_l) {

		EQEvent event = new EQEvent(source);
		event.setEq_h(eq_h);
		event.setEq_h(eq_l);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 设置音量
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void setVolume(LinkEventSource source, VolumeInstance volumeInstance) {

		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.VOLUME);
		event.setVolumeInstance(volumeInstance);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 设置在充电
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void setChageOn(LinkEventSource source) {

		BatteryEvent event = new BatteryEvent(source);
		event.setState(BatteryStatus.CHARGE_ON);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 设置没有在充电
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void setChageOff(LinkEventSource source) {

		BatteryEvent event = new BatteryEvent(source);
		event.setState(BatteryStatus.CHARGE_OFF);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 电量充满
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void setFullYes(LinkEventSource source) {

		BatteryEvent event = new BatteryEvent(source);
		event.setState(BatteryStatus.FULL_YES);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 电量没有充满
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void setFullNo(LinkEventSource source) {

		BatteryEvent event = new BatteryEvent(source);
		event.setState(BatteryStatus.FULL_NO);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 外置电源接入
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void setExternalPowerIn(LinkEventSource source) {

		BatteryEvent event = new BatteryEvent(source);
		event.setState(BatteryStatus.EXTERNAL_POWER_IN);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 设置外置电源离开
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void setExternalPowerOut(LinkEventSource source) {

		BatteryEvent event = new BatteryEvent(source);
		event.setState(BatteryStatus.EXTERNAL_POWER_OUT);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 设置电量的百分比
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void setChagePercent(LinkEventSource source, int percent) {

		BatteryEvent event = new BatteryEvent(source);
		if (percent >= 0 && percent <= 100)
			event.setCharge_percent(percent);
		event.setState(BatteryStatus.CHARGE_PERCNET);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 加音量调用
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void volumeUp(LinkEventSource source) {

		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.VOLUME_UP);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 减音量调用
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void volumeDown(LinkEventSource source) {

		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.VOLUME_DOWN);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 停止的时候调用
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 * @param instanceID
	 */
	@Override
	public void stop(LinkEventSource source, int instanceID) {

		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.STOP);
		event.setInstanceID(instanceID);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 上一首
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void previous(LinkEventSource source, int instanceID) {
		Log.i("WGZ", "LuncherApplication_OpenSwitchSongGesture==="
				+ lApplication.getOpenSwitchSongGesture());
		if (lApplication.getOpenSwitchSongGesture()
				|| source != LinkEventController.serialSource) {
			PlayerEvent event = new PlayerEvent(source);
			event.setType(PlayerStatus.PREVIOUS);
			event.setInstanceID(instanceID);
			LinkEventController.getInstance().notifyListeners(event);
		}
	}

	/**
	 * 下一首
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void next(LinkEventSource source, int instanceID) {

		Log.i("WGZ", "LuncherApplication_OpenSwitchSongGesture==="
				+ lApplication.getOpenSwitchSongGesture());
		if (lApplication.getOpenSwitchSongGesture()
				|| source != LinkEventController.serialSource) {

			PlayerEvent event = new PlayerEvent(source);
			event.setType(PlayerStatus.NEXT);
			event.setInstanceID(instanceID);
			LinkEventController.getInstance().notifyListeners(event);
		}
	}

	/**
	 * 语音开始
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void speechStart(LinkEventSource source) {

		SpechEvent event = new SpechEvent(source);
		event.setSpechStatus(SpeechStatus.SPEECHSTART);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 语音结束
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void speechStop(LinkEventSource source) {

		SpechEvent event = new SpechEvent(source);
		event.setSpechStatus(SpeechStatus.SPEECHSTOP);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 请求得到音量
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestVolume(LinkEventSource source, int instanceID) {

		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.VOLUME);
		event.setInstanceID(instanceID);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 请求得到系统的状态
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestState(LinkEventSource source) {

		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.STATE);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 响应硬件版本号
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void responseHardWareVersion(LinkEventSource source, String s) {

		ResponceEvent event = new ResponceEvent(source);
		event.setHardwareVersion(s);
		event.setResponceStatus(ResponceStatus.HARDWARE_VERSION);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 订阅
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */

	@Override
	public void subscribe(LinkEventSource source, ControlDriver controlDriver) {

		LanEvent event = new LanEvent(source);
		event.setControlDriver(controlDriver);
		event.setLanStatus(LanStatus.SUBSCRIBE);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 取消订阅
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void unsubscribe(LinkEventSource source, ControlDriver controlDriver) {

		LanEvent event = new LanEvent(source);
		event.setControlDriver(controlDriver);
		event.setLanStatus(LanStatus.UNSUBSCRIBE);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 推送歌曲的时候调用
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void addUriToQueue(LinkEventSource source, UriToQueue uriToQueue) {
		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.ADD_URI_TO_QUEUE);
		event.setUriToQueue(uriToQueue);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 设置暂停
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 * @param instanceID
	 */
	@Override
	public void pause(LinkEventSource source, int instanceID) {
		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.PAUSE);
		event.setInstanceID(instanceID);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 设置播放模式
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void setPlayMode(LinkEventSource source, String playMode) {
		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.PLAY_MODE);
		event.setPlayMode(playMode);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 设置喜欢这首歌
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void favorite(LinkEventSource source, FavoriteBean favoriteBean) {

		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.FAVORITE);
		event.setFavoriteOrder(favoriteBean);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 删除当前歌曲
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void delete(LinkEventSource source, DeleteBean deleteBean) {
		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.DELETE);
		event.setDeleteOrder(deleteBean);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 设置进度
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void setProgress(LinkEventSource source, Seek seek) {
		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.PROGRESS);
		event.setSeek(seek);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 请求得到系统版本
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestVersion(LinkEventSource source, ZoneInfo zoneInfo) {
		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.VERSION);
		event.setZoneInfo(zoneInfo);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 请求得到进度
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestProgress(LinkEventSource source, int instanceID) {
		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.PROGRESS);
		event.setInstanceID(instanceID);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 请求得到当前歌曲的信息
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestSongInfo(LinkEventSource source) {
		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.SONG_INFO);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 请求得到当前歌曲的目录
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestCategory(LinkEventSource source) {
		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.CATEGORY);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 请求得到播放模式
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestPlayMode(LinkEventSource source) {
		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.PLAY_MODE);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 请求得到所有状态
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestAllStatus(LinkEventSource source, int instanceID) {
		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.ALL_STAUS);
		event.setInstanceID(instanceID);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 请求得到播放状态
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void requestPlayStatus(LinkEventSource source) {
		RequestEvent event = new RequestEvent(source);
		event.setRequestStatus(RequestStatus.PLAY_STATUS);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 响应当前系统版本号
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void responseVersion(LinkEventSource source, ZoneInfo zoneInfo) {
		ResponceEvent event = new ResponceEvent(source);
		event.setResponceStatus(ResponceStatus.VERSION);
		event.setZoneInfo(zoneInfo);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 响应播放状态
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void responsePlayStatus(LinkEventSource source, String playStatus) {
		ResponceEvent event = new ResponceEvent(source);
		event.setResponceStatus(ResponceStatus.PLAY_STATUS);
		event.setPlayStatus(playStatus);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 响应进度
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void responsePositionInfo(LinkEventSource source,
			PositionInfo positionInfo) {
		ResponceEvent event = new ResponceEvent(source);
		event.setResponceStatus(ResponceStatus.POSITION_INFO);
		event.setPositionInfo(positionInfo);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 响应音量
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */

	@Override
	public void responseVolume(LinkEventSource source, ResponseVolume volume) {
		ResponceEvent event = new ResponceEvent(source);
		event.setResponceStatus(ResponceStatus.VOLUME);
		event.setVolume(volume);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 响应当前的歌曲信息
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */

	@Override
	public void responseSongInfo(LinkEventSource source, SongInfo songInfo) {
		ResponceEvent event = new ResponceEvent(source);
		event.setResponceStatus(ResponceStatus.SONGINFO);
		event.setSonginfo(songInfo);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 响应当前歌曲的目录
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void responseCategory(LinkEventSource source, String category) {
		ResponceEvent event = new ResponceEvent(source);
		event.setResponceStatus(ResponceStatus.CATEGORY);
		event.setCategory(category);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 响应播放状态
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void responsePlayMode(LinkEventSource source, String playMode) {
		ResponceEvent event = new ResponceEvent(source);
		event.setResponceStatus(ResponceStatus.PLAY_MODE);
		event.setPlaymode(playMode);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 响应当前的所有状态
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void responseAllStatus(LinkEventSource source,
			MediaStateInstance instances) {
		ResponceEvent event = new ResponceEvent(source);
		event.setResponceStatus(ResponceStatus.ALL_STATUS);
		event.setInstances(instances);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 切歌时候调用
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 */
	@Override
	public void notyfiStateChange(LinkEventSource source,
			MediaStateInstance instances) {
		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.MEDIA_STATE);
		event.setInstances(instances);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 响应系统状态
	 * 
	 * @param source
	 *            LinkEventChontroller的静态变量
	 * @param responceStatus
	 */
	@Override
	public void responseSystemStatus(LinkEventSource source,
			ResponceStatus responceStatus) {
		ResponceEvent event = new ResponceEvent(source);
		event.setResponceStatus(responceStatus);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 播放状态切换，如果暂停就播放，如果播放就暂停
	 */
	@Override
	public void shift(LinkEventSource source) {
		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.SHIFT);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 打开局域网服务
	 */
	@Override
	public void openService(LinkEventSource source, int port) {
		LanEvent event = new LanEvent(source);
		event.setLanStatus(LanStatus.OPEN_SERVICE);
		event.setPort(port);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 局域网服务打开成功或失败
	 */
	@Override
	public void openServiceCallback(LinkEventSource source,
			boolean isOpenServiceCallback) {
		LanEvent event = new LanEvent(source);
		event.setLanStatus(LanStatus.OPEN_SERVICE_CALLBACK);
		event.setOpenServiceCallback(isOpenServiceCallback);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 关闭局域网服务
	 */
	@Override
	public void closeService(LinkEventSource source) {
		LanEvent event = new LanEvent(source);
		event.setLanStatus(LanStatus.CLOSE_SERVICE);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 局域网服务关闭成功或失败
	 */
	@Override
	public void closeServiceCallback(LinkEventSource source,
			boolean isCloseServiceCallback) {
		LanEvent event = new LanEvent(source);
		event.setLanStatus(LanStatus.CLOSE_SERVCE_CALLBACK);
		event.setCloseServiceCallback(isCloseServiceCallback);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * wifi状态通知
	 */
	@Override
	public void wifiConnected(LinkEventSource source, boolean wifiConnected,
			String wifiName) {
		LanEvent event = new LanEvent(source);
		event.setWificonnected(wifiConnected);
		event.setLanStatus(LanStatus.WIFI_CONNECTED);
		event.setWifiName(wifiName);
		LinkEventController.getInstance().notifyListeners(event);

	}

	@Override
	public void updateStart(LinkEventSource source) {
		UpdateEvent event = new UpdateEvent(source);
		event.setState(UpdateStatus.PRE_UPDATE);
		LinkEventController.getInstance().notifyListeners(event);
	}

	@Override
	public void updateEnd(LinkEventSource source) {
		UpdateEvent event = new UpdateEvent(source);
		event.setState(UpdateStatus.AFTER_UPDATE);
		LinkEventController.getInstance().notifyListeners(event);
	}

	@Override
	public void serviceAdded(LinkEventSource source, McServiceMsg msg) {
		LanEvent event = new LanEvent(source);
		event.setLanStatus(LanStatus.SERVICE_ADDED);
		event.setMcServiceMsg(msg);
		LinkEventController.getInstance().notifyListeners(event);
	}

	/**
	 * 进入屏保
	 */
	@Override
	public void isScreenProtect(LinkEventSource source) {
		SystemStateEvent event = new SystemStateEvent(source);
		event.setWorkStatus(SystemStatus.SCREEN_PROTECT);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 有动作，进入正常
	 */
	@Override
	public void hasAction(LinkEventSource source) {
		SystemStateEvent event = new SystemStateEvent(source);
		event.setWorkStatus(SystemStatus.HAS_ACTION);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 语音时候的音量大小
	 * 
	 * @param source
	 * @param volume
	 *            音量大小【0~31】
	 */
	@Override
	public void speechVolume(LinkEventSource source, int volume) {
		SpechEvent event = new SpechEvent(source);
		event.setVolume(volume);
		event.setSpechStatus(SpeechStatus.SPEECH_VOLUME);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 语音的返回结果
	 * 
	 * @param source
	 * @param string
	 */
	@Override
	public void speechUnderstandRs(LinkEventSource source, String string) {
		SpechEvent event = new SpechEvent(source);
		event.setStrResult(string);
		event.setSpechStatus(SpeechStatus.SPEECH_RESULT_STRING);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 语音的返回结果
	 * 
	 * @param source
	 * @param result
	 */
	@Override
	public void speechUnderstandRs(LinkEventSource source, SemanticObj result) {
		Log.d("timer", "linkSDK=======================speechUnderstandRs");
		SpechEvent event = new SpechEvent(source);
		event.setSemanticObj(result);
		event.setSpechStatus(SpeechStatus.SPEECH_RESULT_OBJECT);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 用户说完了
	 */
	@Override
	public void speechEnd(LinkEventSource source) {
		SpechEvent event = new SpechEvent(source);
		event.setSpechStatus(SpeechStatus.SPEECH_END);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 语音识别失败
	 */
	@Override
	public void speechUnderstandError(LinkEventSource source, String error) {
		SpechEvent event = new SpechEvent(source);
		event.setStrError(error);
		event.setSpechStatus(SpeechStatus.SPEECH_UNDERSTAND_ERROR);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 语音合成完成
	 */
	@Override
	public void speechSpeakComplite(LinkEventSource source, boolean isWake) {
		SpechEvent event = new SpechEvent(source);
		event.setWake(isWake);
		event.setSpechStatus(SpeechStatus.SPEECH_SPEECK_COMPLITE);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 开始语音合成
	 */
	@Override
	public void speechStartSpeakString(LinkEventSource source, String speakStr) {
		SpechEvent event = new SpechEvent(source);
		event.setSpeakString(speakStr);
		event.setSpechStatus(SpeechStatus.SPEECH_START_SPEAK);
		LinkEventController.getInstance().notifyListeners(event);

	}

	/**
	 * 停止语音合成
	 */
	@Override
	public void speechStopSpeak(LinkEventSource source) {
		SpechEvent event = new SpechEvent(source);
		event.setSpechStatus(SpeechStatus.SPEECH_STOP_SPEAK);
		LinkEventController.getInstance().notifyListeners(event);

	}

	// @Override
	// public void sendVolume(LinkEventSource source, VolumeInstance instance) {
	// PlayerEvent event = new PlayerEvent(source);
	// event.setType(PlayerStatus.SEND_VOLUME);
	// event.setVolumeInstance(instance);
	// LinkEventController.getInstance().notifyListeners(event);
	//
	// }

	@Override
	public void setAVTransportUri(LinkEventSource source,
			AVTransportUri avTransportUri) {
		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.SET_AV_TRANSPORT_URI);
		event.setAvTransportUri(avTransportUri);
		LinkEventController.getInstance().notifyListeners(event);

	}

	@Override
	public void addUriToQueueResponse(LinkEventSource source,
			ResponseUriToQueue responseUriToQueue) {
		PlayerEvent event = new PlayerEvent(source);
		event.setType(PlayerStatus.ADD_URI_TO_QUEUE_RESPONSE);
		event.setResponseUriToQueue(responseUriToQueue);
		LinkEventController.getInstance().notifyListeners(event);

	}

	@Override
	public void setLow(LinkEventSource source) {
		// TODO Auto-generated method stub
		BatteryEvent event = new BatteryEvent(source);
		event.setState(BatteryStatus.Battery_LOW);
		LinkEventController.getInstance().notifyListeners(event);
	}

	@Override
	public void serviceDelete(LinkEventSource source, String name) {
		LanEvent event = new LanEvent(source);
		event.setServiceName(name);
		event.setLanStatus(LanStatus.SERVICE_DELETE);
		LinkEventController.getInstance().notifyListeners(event);
	}

	@Override
	public void setVoltage(LinkEventSource source, float a) {
		BatteryEvent event = new BatteryEvent(source);
		event.setState(BatteryStatus.BATTERY_VOLTAGE);
		event.setVoltage(a);
		LinkEventController.getInstance().notifyListeners(event);

	}

	@Override
	public void notifyMCServices(LinkEventSource source,
			List<McServiceMsg> mcServiceMsgs, String uuid) {
		LanEvent event = new LanEvent(source);
		event.setMcServiceMsgs(mcServiceMsgs);
		event.setUuid(uuid);
		event.setLanStatus(LanStatus.SERVICE_NOTIFY);
		LinkEventController.getInstance().notifyListeners(event);
	}
}
